﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QLK.Database;
using QLK.Web.App_Code;
using QLK.Database.BLLs;

namespace QLK.Web
{
    public partial class SupplierManagement : System.Web.UI.Page
    {
        public int _iStt = 1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadAllSuppliers();
            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect(PageUrls.SupplierDetails);
        }

        protected void imgDelete_Click(object sender, ImageClickEventArgs e)
        {

        }

        protected void imgEdit_Click(object sender, ImageClickEventArgs e)
        {
            //Get gridview index
            GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
            int index = gvRow.RowIndex;

            Supplier supp = new Supplier();
            supp.SupplierName = GridSupplier.Rows[index].Cells[1].Text.ToString();
            supp.Address = GridSupplier.Rows[index].Cells[2].Text.ToString();
            supp.PhoneNumber = GridSupplier.Rows[index].Cells[3].Text.ToString();
            ImageButton img = sender as ImageButton;
            Response.Redirect(string.Format("{0}?{1}={2}&{3}={4}&{5}={6}&{7}={8}", PageUrls.SupplierDetails,
                Columns.SupplierID,img.CommandArgument,Columns.SupplierName,supp.SupplierName,
                Columns.Address,supp.Address,Columns.PhoneNumber,supp.PhoneNumber));
        }

        private void LoadAllSuppliers()
        {
            SupplierBLL bll = new SupplierBLL();
            GridSupplier.DataSource = bll.GetAllSupplier();
            GridSupplier.DataBind();
        }
    }
}
